package UI
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;

	public class UIEdit extends Sprite
	{
		public var mText:TextField=null;
		public var mfocusOutFunc:Function=null;
		public var mWidth:Number=0;
		public var mHeight:Number=0;
		
		public function UIEdit()
		{
			super();
		}
		
		public function Create(x:int,y:int,w:int,h:int,focusOutFunc:Function):Boolean
		{
			this.x=x;
			this.y=y;
			mWidth=w;
			mHeight=h;
			
			mText=new TextField;
			addChild(mText);
			mText.defaultTextFormat=UIManager.msInstance.mUITextFormat;
			mText.textColor=0x111111;
			mText.type=TextFieldType.INPUT;
			mText.x=0;
			mText.y=0;
			mText.width=w;
			mText.height=h;
			mText.focusRect=true;
			
			mText.addEventListener(FocusEvent.FOCUS_OUT,OnFocusOut);
			addEventListener(MouseEvent.MOUSE_DOWN,OnMouseClick);
			
			mfocusOutFunc=focusOutFunc;
			
			//绘制边框
			graphics.lineStyle(1,0x111111);
			graphics.beginFill(0xEEEEEE,0.2);
			graphics.drawRoundRect(0,0,mWidth,mHeight,4,4);
			graphics.endFill();
			return true;
		}
		
		public function SetText(text:String):void
		{
			mText.text=text;
		}
		
		public function OnMouseClick(event:MouseEvent):void
		{
			event.stopImmediatePropagation();			
		}
		
		public function OnFocusOut(event:FocusEvent):void
		{
			if(mfocusOutFunc!=null)
				mfocusOutFunc();
		}
	}
}